<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/6/21
 * Time: 下午3:28
 */

namespace app\index\model;


use app\index\service\CategoryService;
use think\Model;

class Consult extends Model
{
    protected $table = "t_consult";
    public static function getRecList(){
        $data = self::where("status","=",1)->where("flag","=",1)
            ->order("created_at desc")
            ->limit(0,5)->select();
        if($data->isEmpty()){
            return[];
        }
        $consult_list = [];
        foreach ($data as $item){
            $consult_item['phone'] = substr_replace($item['phone'],'****',3,4);
            $consult_item['address'] = $item['address'];
            $consult_item['create_time'] = substr($item['created_at'],0,10);
            $consult_item["category_name"] = CategoryService::getCategoryNamesBySubCateId($item["subcategory_id"]);
            array_push($consult_list,$consult_item);
        }
        return $consult_list;


    }
    public static function getTotalNum(){
        $data = self::where("status","=",1)->where("flag","=",1)->select();
        if($data->isEmpty()){
            return 0;
        }
        return $data->count();

    }
}